package com.example.tests;

import org.junit.*;
import static org.junit.Assert.*;
import com.example.pages.UsersPage;
import com.example.common.*;

public class CreateNewUser extends TestBase {
	@Test
	public void testCreateNewUser() throws Exception {
		String user1 = HskFunctions.generateRandomName("user", 10);

		UsersPage userPage = goToMainPage().loginWithValidCredentials("admin",
				"admin").gotoUserManagementPage();

		SortedListOf<User> oldUserList = userPage.getUsers();

		User user = new User().withName(user1).withEmail(user1 + "@test.ru")
				.withPassword(user1);
	
		if (oldUserList.contains(user)) {
			userPage.deleteUser(user);
			oldUserList = userPage.getUsers();
		}

		userPage.createUser(user);

		SortedListOf<User> newUserList = userPage.getUsers();

		assertEquals(newUserList, oldUserList.withAdded(user));
		userPage.logout();
	}
}